// @/api/xiaoquan.js
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import request from "@/utils/request";
import http from "@/utils/requesttwo"
dayjs.extend(relativeTime);

// 模拟数据
const mockData = {
	// 热榜数据
	hotList: [{
			id: 1,
			title: "现在还有人没睡吗？聊会天",
			heat: "2345"
		},
		{
			id: 2,
			title: "图书馆自习室预约系统升级",
			heat: "1890"
		},
		{
			id: 3,
			title: "周末校园义诊活动通知",
			heat: "1234"
		},
		{
			id: 4,
			title: "食堂新推出的麻辣香锅太好吃了",
			heat: "987"
		},
		{
			id: 5,
			title: "校园篮球赛即将开始，各班报名中",
			heat: "765"
		}
	],

	// 分类数据
	categories: [{
			id: "1",
			name: "最新"
		},
		{
			id: "2",
			name: "新鲜事"
		},
		{
			id: "3",
			name: "交友"
		},
		{
			id: "4",
			name: "日常投稿"
		},
		{
			id: "5",
			name: "拼车"
		},
		{
			id: "6",
			name: "二手交易"
		},
		{
			id: "7",
			name: "寻物启事"
		}
	],

	// 帖子数据
	posts: [{
			id: "1001",
			content: "有拼车去邯郸的吗？价格可谈！周六早上出发，有车，还可以坐3个人，有意者留言。",
			createtime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "https://paole.hebeixiaoyu.cn/run/profile/upload/ceshi.png",
				username: "神秘同学",
				sex: "男",
				isEdit: false,
			},
			depname: "拼车",
			typeid: "5",
			commentnum: 3,
			likestatus: 0,
			likenum: 2,
			hover: false,
			tags: ["拼车"]
		},
		{
			id: "1002",
			content: "有没有同学周日一起约爬山的，早上八点学校大门口集合！预计下午回来，山上有农家乐可以吃饭，费用AA。",
			createtime: dayjs().subtract(1, 'day').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "https://paole.hebeixiaoyu.cn/run/profile/upload/ceshi.png",
				username: "神秘同学",
				sex: "女",
				isEdit: false,
			},
			depname: "交友",
			typeid: "3",
			commentnum: 8,
			likestatus: 1,
			likenum: 15,
			hover: false,
			tags: ["交友"]
		},
		{
			id: "1003",
			content: "因换了新电脑，现出售一台自用的联想笔记本，九成新，配置如下：i5-10210U处理器，8G内存，512G固态硬盘，MX350独立显卡，使用不到一年，无任何故障，价格可小刀~",
			createtime: dayjs().subtract(2, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "https://paole.hebeixiaoyu.cn/run/profile/upload/ceshi.png",
				username: "神秘同学",
				sex: "男",
				isEdit: false,
			},
			depname: "二手交易",
			typeid: "6",
			commentnum: 5,
			likestatus: 0,
			likenum: 9,
			hover: false,
			tags: ["二手交易"]
		},
		{
			id: "1004",
			content: "捡到一个钱包，里面有身份证和一些现金，失主请联系我！",
			createtime: dayjs().subtract(3, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "/static/image/default-avatar.png",
				username: "热心同学",
				sex: "女",
				isEdit: false,
			},
			depname: "寻物启事",
			typeid: "7",
			commentnum: 12,
			likestatus: 1,
			likenum: 20,
			hover: false,
			tags: ["寻物启事"]
		},
		{
			id: "1005",
			content: "今天食堂的麻辣香锅真的太好吃了，推荐大家去试试！",
			createtime: dayjs().subtract(4, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "/static/image/default-avatar.png",
				username: "美食爱好者",
				sex: "男",
				isEdit: false,
			},
			depname: "新鲜事",
			typeid: "2",
			commentnum: 7,
			likestatus: 0,
			likenum: 14,
			hover: false,
			tags: ["新鲜事"]
		},
		{
			id: "1006",
			content: "有人想一起组队参加编程竞赛吗？我有一些经验，想找几个队友一起努力！",
			createtime: dayjs().subtract(5, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "https://paole.hebeixiaoyu.cn/run/profile/upload/ceshi.png",
				username: "编程达人",
				sex: "男",
				isEdit: false,
			},
			depname: "日常投稿",
			typeid: "4",
			commentnum: 9,
			likestatus: 1,
			likenum: 18,
			hover: false,
			tags: ["日常投稿"]
		},
		{
			id: "1007",
			content: "出一套考研资料，几乎全新，价格优惠，有意者联系！",
			createtime: dayjs().subtract(6, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "/static/image/default-avatar.png",
				username: "上岸学姐",
				sex: "女",
				isEdit: false,
			},
			depname: "二手交易",
			typeid: "6",
			commentnum: 4,
			likestatus: 0,
			likenum: 7,
			hover: false,
			tags: ["二手交易"]
		},
		{
			id: "1008",
			content: "周末去图书馆学习的有没有？一起占座呀！",
			createtime: dayjs().subtract(7, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "https://paole.hebeixiaoyu.cn/run/profile/upload/ceshi.png",
				username: "学霸君",
				sex: "男",
				isEdit: false,
			},
			depname: "交友",
			typeid: "3",
			commentnum: 6,
			likestatus: 1,
			likenum: 12,
			hover: false,
			tags: ["交友"]
		},
		{
			id: "1009",
			content: "有人知道学校附近哪里有修手机比较靠谱的地方吗？我的手机屏幕碎了。",
			createtime: dayjs().subtract(8, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "/static/image/default-avatar.png",
				username: "手机党",
				sex: "男",
				isEdit: false,
			},
			depname: "日常投稿",
			typeid: "4",
			commentnum: 10,
			likestatus: 0,
			likenum: 8,
			hover: false,
			tags: ["日常投稿"]
		},
		{
			id: "1010",
			content: "有没有同学要去体育馆打球的？一起呀！",
			createtime: dayjs().subtract(9, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "https://paole.hebeixiaoyu.cn/run/profile/upload/ceshi.png",
				username: "运动达人",
				sex: "男",
				isEdit: false,
			},
			depname: "交友",
			typeid: "3",
			commentnum: 5,
			likestatus: 1,
			likenum: 11,
			hover: false,
			tags: ["交友"]
		},
		{
			id: "1011",
			content: "出售一辆自行车，九成新，价格便宜，有意者联系！",
			createtime: dayjs().subtract(10, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "/static/image/default-avatar.png",
				username: "毕业生",
				sex: "女",
				isEdit: false,
			},
			depname: "二手交易",
			typeid: "6",
			commentnum: 3,
			likestatus: 0,
			likenum: 6,
			hover: false,
			tags: ["二手交易"]
		},
		{
			id: "1012",
			content: "捡到一本书，《Java编程思想》，失主联系我！",
			createtime: dayjs().subtract(11, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "https://paole.hebeixiaoyu.cn/run/profile/upload/ceshi.png",
				username: "拾金不昧",
				sex: "男",
				isEdit: false,
			},
			depname: "寻物启事",
			typeid: "7",
			commentnum: 8,
			likestatus: 1,
			likenum: 13,
			hover: false,
			tags: ["寻物启事"]
		},
		{
			id: "1013",
			content: "校园羽毛球比赛报名开始啦，欢迎各位同学踊跃参加！",
			createtime: dayjs().subtract(12, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "/static/image/default-avatar.png",
				username: "体育委员",
				sex: "男",
				isEdit: false,
			},
			depname: "新鲜事",
			typeid: "2",
			commentnum: 15,
			likestatus: 0,
			likenum: 22,
			hover: false,
			tags: ["新鲜事"]
		},
		{
			id: "1014",
			content: "求购一本《数据结构与算法分析》教材，有的同学联系我！",
			createtime: dayjs().subtract(13, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "https://paole.hebeixiaoyu.cn/run/profile/upload/ceshi.png",
				username: "学习委员",
				sex: "女",
				isEdit: false,
			},
			depname: "日常投稿",
			typeid: "4",
			commentnum: 7,
			likestatus: 1,
			likenum: 10,
			hover: false,
			tags: ["日常投稿"]
		},
		{
			id: "1015",
			content: "有没有同学一起拼车去火车站？下周五下午的车。",
			createtime: dayjs().subtract(14, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "/static/image/default-avatar.png",
				username: "返乡游子",
				sex: "男",
				isEdit: false,
			},
			depname: "拼车",
			typeid: "5",
			commentnum: 4,
			likestatus: 0,
			likenum: 5,
			hover: false,
			tags: ["拼车"]
		},
		{
			id: "1016",
			content: "出售一台闲置的打印机，使用不到半年，功能完好，价格面议。",
			createtime: dayjs().subtract(15, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "https://paole.hebeixiaoyu.cn/run/profile/upload/ceshi.png",
				username: "毕业生",
				sex: "女",
				isEdit: false,
			},
			depname: "二手交易",
			typeid: "6",
			commentnum: 6,
			likestatus: 1,
			likenum: 14,
			hover: false,
			tags: ["二手交易"]
		},
		{
			id: "1017",
			content: "捡到一个校园卡，失主请联系我认领。",
			createtime: dayjs().subtract(16, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "/static/image/default-avatar.png",
				username: "好心人",
				sex: "男",
				isEdit: false,
			},
			depname: "寻物启事",
			typeid: "7",
			commentnum: 9,
			likestatus: 0,
			likenum: 17,
			hover: false,
			tags: ["寻物启事"]
		},
		{
			id: "1018",
			content: "周末有没有一起去图书馆复习的？约个伴呀！",
			createtime: dayjs().subtract(17, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "https://paole.hebeixiaoyu.cn/run/profile/upload/ceshi.png",
				username: "学霸",
				sex: "女",
				isEdit: false,
			},
			depname: "交友",
			typeid: "3",
			commentnum: 8,
			likestatus: 1,
			likenum: 19,
			hover: false,
			tags: ["交友"]
		},
		{
			id: "1019",
			content: "学校附近新开了一家奶茶店，味道超棒，推荐给大家！",
			createtime: dayjs().subtract(18, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "/static/image/default-avatar.png",
				username: "美食达人",
				sex: "男",
				isEdit: false,
			},
			depname: "新鲜事",
			typeid: "2",
			commentnum: 12,
			likestatus: 0,
			likenum: 25,
			hover: false,
			tags: ["新鲜事"]
		},
		{
			id: "1020",
			content: "出售一批考研资料，包括专业课和公共课，几乎全新。",
			createtime: dayjs().subtract(19, 'days').format('YYYY-MM-DD HH:mm:ss'),
			user: {
				avatar_text: "https://paole.hebeixiaoyu.cn/run/profile/upload/ceshi.png",
				username: "上岸学长",
				sex: "男",
				isEdit: false,
			},
			depname: "二手交易",
			typeid: "6",
			commentnum: 5,
			likestatus: 1,
			likenum: 13,
			hover: false,
			tags: ["二手交易"]
		}
	]
};

// 模拟网络请求延迟
const requestDelay = (data, delay = 800) => {
	return new Promise(resolve => {
		setTimeout(() => {
			resolve({
				code: 200,
				data,
				message: '请求成功'
			});
		}, delay);
	});
};

// 获取热榜数据
// export const getHotList = (schoolId) => {
//   return requestDelay(mockData.hotList);
// };
export const getHotList = (schoolId) => {
	let responst = request({
		url: '/api/front/hitch/passengerManager/rebang/list',
		method: 'get',
		data: {
			schoolId
		}
	});
	return responst;
}

// 获取分类数据
export const getCategories = () => {
	let responst = request({
		url: '/api/front/hitch/passengerManager/tiezifenlei/list',
		method: 'get'
	});
	console.log("分类数据：  ", responst)
	return responst;
};

// // 获取帖子列表（支持分页和筛选）
// // pageNo 查询的页面第几页    pageSize.value 页面总页数    categoryId 分类id   searchKey 搜索框内容--但现在不需要这个字段了
// export const getPosts = (pageNo = 1, pageSize = 10, categoryId = null, schoolId = '') => {
//   let posts = [...mockData.posts];

//   // 搜索过滤
//   if (searchKey) {
//     const searchTerm = searchKey.toLowerCase().trim();
//     posts = posts.filter(post => 
//       post.content.toLowerCase().includes(searchTerm) || 
//       post.user?.username?.toLowerCase().includes(searchTerm)
//     );
//   }

//   // 分类过滤
//   if (categoryId && categoryId !== "1") {
//     const categoryName = mockData.categories.find(c => c.id === categoryId)?.name;
//     if (categoryName) {
//       posts = posts.filter(post => post.tags.includes(categoryName));
//     }
//   }

//   // 分页
//   const start = (pageNo - 1) * pageSize;
//   const end = pageNo * pageSize;
//   const currentPageData = posts.slice(start, end);

//   // 判断是否还有更多数据
//   const hasMore = end < posts.length;

//   return requestDelay({
//     list: currentPageData,
//     hasMore
//   });
// };


// 获取搜索数据，不分类，分页
export const getSouSuo = (pageNo = 1, pageSize = 10, schoolId = '', neirong = '') => {
	let responst = request({
		url: '/api/front/hitch/passengerManager/tiezi/getSouSuo',
		method: 'get',
		data: {
			pageNo,
			pageSize,

			schoolId,
			neirong
		}
	});
	console.log("帖子数据：1getSouSuo  ", responst)
	return responst;
};


// 获取帖子列表（支持分页和筛选）
// pageNo 查询的页面第几页    pageSize.value 页面总页数    categoryId 分类id   searchKey 搜索框内容--但现在不需要这个字段了
export const getZhiDingTieZi = (tiezileibie = null, schoolId = '') => {
	let responst = request({
		url: '/api/front/hitch/passengerManager/tiezi/getZhiDingTieZi',
		method: 'get',
		data: {
			tiezileibie,
			schoolId
		}
	});
	console.log("帖子数据getZhiDingTieZi  ", responst)
	return responst;
};

// 获取帖子列表（支持分页和筛选）
// pageNo 查询的页面第几页    pageSize.value 页面总页数    categoryId 分类id   searchKey 搜索框内容--但现在不需要这个字段了
export const getPosts = (pageNo = 1, pageSize = 10, tiezileibie = null, schoolId = '') => {
	let responst = request({
		url: '/api/front/hitch/passengerManager/tiezi/list',
		method: 'get',
		data: {
			pageNo,
			pageSize,
			tiezileibie,
			schoolId
		}
	});
	console.log("帖子数据：getPosts  ", responst)
	return responst;
};


// 发布帖子接口
export const publishPost = (data) => {
	console.log(data)

	return http.post(`/api/front/hitch/passengerManager/tiezi/fabu`, data)
}
export const commentPost = (data) => {
	console.log(data)

	return http.post(`/api/front/hitch/passengerManager/tiezi/faPingLun`, data)
}


// 获取学校id
export const getSchoolIdBy = () => {


	return http.get(`/api/front/hitch/passengerManager/tiezi/getSchoolIdBy`)
}
// 点赞帖子
export const likePost = (id, likeStetus) => {
	console.log("likePost", id, likeStetus)

	return http.get(`/api/front/hitch/passengerManager/tiezi/likePost?id=${id}&likeStetus=${likeStetus}`)
}

// 获取详情接口
export const getDetail = (id) => {
	console.log(id)
	let responst = request({
		url: '/api/front/hitch/passengerManager/tiezi/getDetail',
		method: 'get',
		data: {
			id
		}
	});
	console.log("帖子id：getDetail  ", responst)
	return responst;

}

// 添加帖子浏览量
export const addTieZiLiuLan = (id) => {
	console.log(id)
	let responst = request({
		url: '/api/front/hitch/passengerManager/tiezi/addTieZiLiuLan',
		method: 'get',
		data: {
			id
		}
	});
	console.log("帖子id：addTieZiLiuLan  ", responst)
	return responst;

}



// 举报贴贴
export const juBaoTieTie = (data) => {
	console.log(data)

	return http.post(`/api/front/hitch/passengerManager/tiezi/juBaoTieTie`, data)
}



export const deletePost = (id) => {

	return http.get(`/api/front/hitch/passengerManager/tiezi/deletePost?id=${id}`)
}


/*消息*/
export const getMesslist = (id) => {
	if (id == undefined) {
		id = '';
	}
	return http.get(`/api/front/hitch/passengerManager/tiezi/xiaoXiList?atype=${id}`)
}

// 宿舍超市微信支付
export const addOrderChongZhiInfo = (data) => {
	return http.post('/api/front/hitch/passengerManager/tiezi/addOrderChongZhiInfo', data);
	// return request({
	// 	url: '/api/front/hitch/passengerManager/tiezi/addOrderChongZhiInfo',
	// 	method: "POST",
	// 	data
	// })
}


// 宿舍超市微信支付
export const createChongZhiOrder = (data) => {
	return request({
		url: '/api/front/hitch/pay/createChongZhiOrder',
		method: "POST",
		data
	})
}

// 修改充值订单状态
export const updateChongZhiOrderStatus = (data) => {
	return request({
		url: '/api/front/hitch/passengerManager/tiezi/updateChongZhiOrderStatus',
		method: "POST",
		data
	})
}


// 搜索是否有会员，和会员到期时间
export const selectIsVipAndVipTime = () => {
	return http.get('/api/front/hitch/passengerManager/vip/selectIsVipAndVipTime');
}



// 宿舍超市微信支付
export const addOrderVipInfo = (data) => {
	return http.post('/api/front/hitch/passengerManager/vip/addOrderVipInfo', data);
	// return request({
	// 	url: '/api/front/hitch/passengerManager/tiezi/addOrderChongZhiInfo',
	// 	method: "POST",
	// 	data
	// })
}


// 宿舍超市微信支付
export const createVipOrder = (data) => {
	return request({
		url: '/api/front/hitch/pay/createVipOrder',
		method: "POST",
		data
	})
}

// 修改充值订单状态
export const updateVipOrderStatus = (data) => {
	return request({
		url: '/api/front/hitch/passengerManager/vip/updateVipOrderStatus',
		method: "POST",
		data
	})
}


// 提现
export const tiXian = (tiXianMoney) => {
	let data = {
		tiXianMoney: tiXianMoney
	}
	return http.post(`/api/front/hitch/passengerManager/test/transfer`, data)
}

// 提现
export const chaXunPeiZhiHeGe = (tiXianMoney) => {
	let data = {
		tiXianMoney: tiXianMoney
	}
	return http.post(`/api/front/hitch/passengerManager/test/chaXunPeiZhiHeGe`, data)
}

// 提现
export const addLiuShuiDelYuEr = (tiXianMoney) => {
	let data = {
		tiXianMoney: tiXianMoney
	}
	return http.post(`/api/front/hitch/passengerManager/test/addLiuShuiDelYuEr`, data)
}


// 获取转账信息
export const getTransferInfo = (outBillNo) => {

	return http.get(`/api/front/hitch/passengerManager/transfer/info?outBillNo=${outBillNo}`)
}


// 添加到商户申请
export const addShangHuShenQing = (data) => {

	return http.post(`/api/front/hitch/passengerManager/shanghu/addShangHuShenQing`, data);
}

// 获取校区管理员手机号 如果没有就找-1 的超级管理员的手机号
export const getSchoolMengerPhone = () => {

	return http.get(`/api/front/hitch/passengerManager/tiezi/getSchoolMengerPhone`)
}

// 资金流水
export const getZiJinLiuShui = () => {

	return http.get(`/api/front/hitch/passengerManager/getZiJinLiuShui`)
}

// 查询用户昨日收益和总收益
export const getShouYi = () => {
	return http.get('/api/front/hitch/passengerManager/getShouYi')
}

// 查询可体现余额和冻结余额
export const getTiXianAndDongJie = () => {
	return http.get('/api/front/hitch/passengerManager/getTiXianAndDongJie')
}

// 查询佣金比例
export const getYongJinBiLi = () => {
	return http.get('/api/front/hitch/passengerManager/getYongJinBiLi')
}


// true 您已经申请，请等待审核
export const isShangHuShenQingGuoMa = () => {
	return http.get('/api/front/hitch/passengerManager/isShangHuShenQingGuoMa')
}


// 提交申请成为接单人
export const shenQingJieDan = (data) => {
	return http.post('/api/front/hitch/passengerManager/shenQingJieDan', data)
}

// -1未申请，其他的是申请状态0=待审核,1=已通过,2=已拒绝
export const jieDanShenQingZhuangTai = () => {
	return http.get('/api/front/hitch/passengerManager/jieDanShenQingZhuangTai')
}